function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function t(e) {
    if (Array.isArray(e)) {
        for (var t = 0, r = Array(e.length); t < e.length; t++) r[t] = e[t];
        return r;
    }
    return Array.from(e);
}

function r(e) {
    return getApp().getTokens().then(function(t) {
        var r = t.accesstoken, n = t.openid;
        if (!r) return new Promise(function(t) {
            Object.assign(e, {
                openid: n,
                realname: "",
                avatar: ""
            }), t();
        });
        Object.assign(e, {
            accesstoken: r
        });
    });
}

function n(e) {
    var t = e.url, n = e.method, i = void 0 === n ? "GET" : n, u = e.data, c = void 0 === u ? {} : u, s = e.header, l = void 0 === s ? {} : s, p = e.complete, v = void 0 === p ? function() {} : p, g = e.query, h = void 0 === g ? {} : g, m = e.upload, y = void 0 === m ? "" : m;
    return r(h).then(function() {
        var e = Object.keys(h).map(function(e) {
            return e + "=" + h[e];
        }).join("&");
        return t += "?" + e, new Promise(function(e, r) {
            var n = a(e, r, v);
            if (y) {
                var u = o({
                    upload: y,
                    data: c
                }), s = u.filePath, d = u.formData;
                wx.uploadFile(f({
                    url: t,
                    filePath: s,
                    name: y,
                    formData: d
                }, n));
            } else {
                var p = getApp().globalData, g = p.fromuid, h = p.fromapp;
                c = Object.assign(c, {
                    fromuid: g || "",
                    fromapp: h || ""
                }), wx.request(f({
                    url: t,
                    method: i,
                    data: c,
                    header: l
                }, n));
            }
        });
    }).then(function(e) {
        return (0, d.default)(e.data.code, "weAppSite") ? new Promise(function() {}) : e;
    });
}

function a(e, t, r) {
    return {
        success: function(r) {
            if ("string" == typeof r.data) try {
                r.data = JSON.parse(r.data.trim());
            } catch (e) {
                console.error("error: ", r.data), t(r.data);
            }
            e(r);
        },
        fail: function(e) {
            console.error("request error: ", e), t(e);
        },
        complete: r
    };
}

function o(e) {
    var t = e.data, r = e.upload, n = {}, a = t[r];
    return delete t[r], Object.keys(t).forEach(function(e) {
        t[e] instanceof Array ? t[e].forEach(function(t, r) {
            n[e + "[" + r + "]"] = t;
        }) : n[e] = t[e];
    }), {
        formData: n,
        filePath: a
    };
}

function i(e) {
    var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : p;
    if (e instanceof Array) {
        var r = c(e, 1)[0], n = void 0 === r ? "GET" : r;
        return "DOWNLOAD" === n ? null : m(t, n.toLowerCase());
    }
    var a = {};
    return Object.keys(e).forEach(function(r) {
        a[r] = i(e[r], t + "/" + r);
    }), a;
}

function u(e) {
    var t = e.url, r = e.method, n = e.header, a = void 0 === n ? {} : n, o = e.data, i = void 0 === o ? {} : o;
    return getApp().getTokens().then(function(e) {
        var n = e.accesstoken, o = e.openid;
        return t = t + (t.indexOf("?") > -1 ? "&" : "?") + "accesstoken=" + n, new Promise(function(e, u) {
            wx.request({
                url: t,
                method: r,
                header: Object.assign({}, a, (0, l.generateHeaderParams)()),
                data: Object.assign({}, i, {
                    accesstoken: n,
                    openid: o
                }),
                success: function(t) {
                    0 == +t.data.code ? e(t.data.data) : u(t);
                },
                fail: u
            });
        });
    });
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var c = function() {
    function e(e, t) {
        var r = [], n = !0, a = !1, o = void 0;
        try {
            for (var i, u = e[Symbol.iterator](); !(n = (i = u.next()).done) && (r.push(i.value), 
            !t || r.length !== t); n = !0) ;
        } catch (e) {
            a = !0, o = e;
        } finally {
            try {
                !n && u.return && u.return();
            } finally {
                if (a) throw o;
            }
        }
        return r;
    }
    return function(t, r) {
        if (Array.isArray(t)) return t;
        if (Symbol.iterator in Object(t)) return e(t, r);
        throw new TypeError("Invalid attempt to destructure non-iterable instance");
    };
}(), f = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
        var r = arguments[t];
        for (var n in r) Object.prototype.hasOwnProperty.call(r, n) && (e[n] = r[n]);
    }
    return e;
};

exports.minicardRequest = u;

var s = e(require("api-config")), d = e(require("../public/pages/signin-page/checkIfNeedSignin")), l = require("../public/utils/api-signature"), p = e(require("./config")).default.host, v = function(e, t) {
    return new Promise(function(r, n) {
        e.formData && (!0 === t && (t = Object.keys(t)), t && t.length && (t.forEach(function(t) {
            e.formData[t] = encodeURIComponent(e.formData[t]);
        }), e.formData.encode = 1)), getApp().getTokens(function(t) {
            wx.uploadFile(Object.assign({}, e, {
                url: e.url + (e.url.includes("?") ? "&" : "?") + "accesstoken=" + t.accesstoken,
                success: function(t) {
                    "string" == typeof t.data && (t.data = JSON.parse(t.data.trim())), "function" == typeof e.success && e.success(t), 
                    r(t);
                },
                fail: function(t) {
                    "function" == typeof e.fail && e.fail(t), n(t);
                }
            }));
        });
    });
}, g = function(e) {
    return e.method = "GET", n(e);
}, h = function(e) {
    return e.method = "POST", n(e);
}, m = function(e) {
    for (var r = arguments.length, a = Array(r > 2 ? r - 2 : 0), o = 2; o < r; o++) a[o - 2] = arguments[o];
    var i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "get", u = {
        request: n,
        upload: v,
        get: g,
        post: h
    };
    return function() {
        var r = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
        if (r.url = e, "function" == typeof u[i]) {
            for (var n = arguments.length, o = Array(n > 1 ? n - 1 : 0), c = 1; c < n; c++) o[c - 1] = arguments[c];
            return u[i].apply(u, [ r ].concat(t(Object.assign([], a, o))));
        }
    };
}, y = i(s.default);

exports.default = f({}, y, {
    site: f({}, y.site),
    get: g,
    post: h,
    upload: v,
    request: n,
    getUserInfo: r,
    minicardRequest: u
});